package org.openclinic.repository;

import java.util.List;

import org.openclinic.domain.Reminder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface ReminderRepository extends JpaRepository<Reminder, Long> {
	
	@Query("FROM Reminder WHERE customer.userId = ?1 ORDER BY reminderId DESC")
	List<Reminder> findByCustomerId(long id);
	
	@Query(nativeQuery = true, value = "SELECT DISTINCT r.* FROM reminder r INNER JOIN openclinic_user c ON c.user_id = r.customer_id INNER JOIN appointment a ON r.customer_id = a.customer_id WHERE important = TRUE AND date_trunc('day', start_date) = date_trunc('day', NOW())")
	List<Reminder> findTodayImportantReminders();
}
